<?php
/*
* Created on 18/05/2006
*
* @author Rafael Guerrero
*/

function xmlFromToDbWorflow($fileLocation) {
echo "<br>entra en la funcion xml2db";
$workflowDefinitionHandler = new WorkflowDefinitionHandler();

$xml_parser = xml_parser_create('ISO-8859-1');
xml_set_object($xml_parser,$workflowDefinitionHandler);
xml_set_element_handler($xml_parser,"startElement","endElement");
xml_set_character_data_handler($xml_parser,"characters");
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, FALSE);

if (!($fp = fopen($fileLocation, "r"))) {
   throw new Exception('no se puede abrir el archivo '.$fileLocation);
}

while ($file_content = fread($fp, 512)) {
	//echo $file_content.'<hr>';
   if (!xml_parse($xml_parser, $file_content, feof($fp))) {
       throw new Exception(sprintf("XML error: %s at line %d",
                   xml_error_string(xml_get_error_code($xml_parser)),
                   xml_get_current_line_number($xml_parser)));
   }
}

xml_parser_free($xml_parser);

$docTypeHandler =& $workflowDefinitionHandler->getDocTypeHandler();
$docType =& $docTypeHandler->getDocType();

$networkHandler =& $workflowDefinitionHandler->getNetworkHandler();

$network =& $networkHandler->getNetwork();

echo $network;
echo "<br>", count($network->placeList);


$docType->setNetworkRef($network);

$transSetListHandler =& $workflowDefinitionHandler->getTransSetListHandler();
$transSetList =&$transSetListHandler->getTransSetList();


$placeSetListHandler =& $workflowDefinitionHandler->getPlaceSetListHandler();
$placeSetList =&$placeSetListHandler->getPlaceSetList();

$network->placeSetList = $placeSetList;

// Creación del vector de incidencia


echo "<br> Red ", $network; 

	$network->initiateNetwork();

echo "<br>comitea la network";

$network->commit();

showPerfInfo();
}
?>